package flink_p1

import org.apache.flink.api.scala.createTypeInformation
import org.apache.flink.streaming.api.scala.{DataStream, StreamExecutionEnvironment}

object FlinkTest_07_Operator {


  def main(args: Array[String]): Unit = {


    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment
    val ds: DataStream[String] = env.fromCollection(List("aa", "bb", "cc", "cc", "cd", "bb"))



    //    ds.map()
    //    ds.flatMap()
    //    ds.print()


    // keyBy 按key聚合
    //  ds.map((_,1)).keyBy(0).sum(1).print()

    //需求，按某个字段的第一个字符聚合求sum
    //    ds.map((_, 1)).keyBy(new KeySelector[(String, Int), String] {
    //      override def getKey(in: (String, Int)): String = {
    //
    //        val c: Char = in._1.charAt(0)
    //        c.toString
    //      }
    //    }).sum(1).print()

    //unio => 数据类型类型一致
    val ds1: DataStream[String] = env.fromCollection(List("aa", "bb", "cc", "cc", "cd", "bb"))
    val ds2: DataStream[String] = env.fromCollection(List("bbb", "ede", "edede"))

    val unionDs: DataStream[String] = ds1.union(ds2)


    env.execute()


  }
}
